/*
 * Copyright (C) 2019 ~ 2022 Uniontech Technology Co., Ltd.
 *
 * Author:     zhangbingyi <zhangbingyi@uniontech.com>
 *
 * Maintainer: zhangbingyi <zhangbingyi@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "modelsettingchangedialog.h"

//#include <DLabel>
//#include <DSuggestButton>

#include <QLabel>
#include <QPushButton>
#include <QScrollArea>

ModelSettingChangeDialog::ModelSettingChangeDialog(QWidget *parent)
    : DDialog(parent)
{
//    setWindowFlag(Qt::WindowStaysOnTopHint);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    setModal(true);
    setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose);
    setIcon(QIcon::fromTheme("deepin-defender"));
    setFixedWidth(380);
    clearContents(); //清除文本
    clearButtons(); //清除按钮

    // 文本
    QLabel *txt = new QLabel(tr("If turned off, malicious programs can run directly. Are you sure you want to turn it off?"), this);
    txt->setAlignment(Qt::AlignCenter);
    txt->setWordWrap(true);
    addContent(txt);

    QPushButton *laterRestartBtn = new QPushButton(this);
    laterRestartBtn->setText(tr("Cancel", "Button"));
    laterRestartBtn->setAttribute(Qt::WA_NoMousePropagation);
    this->insertButton(0, laterRestartBtn, false);

    QPushButton *RebootNowBtn = new QPushButton(this);
    RebootNowBtn->setText(tr("Turn Off", "Button"));
    RebootNowBtn->setAttribute(Qt::WA_NoMousePropagation);
    this->insertButton(1, RebootNowBtn, false);
    // 添加信号槽
    connect(this, SIGNAL(buttonClicked(int, const QString &)), this, SLOT(onRebootBtn(int, const QString&)));
}

ModelSettingChangeDialog::~ModelSettingChangeDialog()
{
    Q_EMIT onDialogClose();
}

void ModelSettingChangeDialog::onRebootBtn(int index, const QString &text)
{
    Q_UNUSED(text)

    if (1 == index) {
        Q_EMIT sendExeFilesModelTurnOff();
    }
    close();
}

